package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.HashMap;

import logic.*;

import javax.swing.*;
import java.awt.*;

/**
 * This view counts the amount of the actors and places 
 * the amount of actors next to the right picture.
 * @author Vossen en Konijnen group 2
 *
 */
public class PictureCounterView extends AbstractView
{
	
	private int rabbitCount;
	private int hunterCount;
	private int duckCount;
	private int foxCount;
	private int grassCount;
	private ImageIcon rabbitImage;
	private ImageIcon foxImage;
	private ImageIcon duckImage;
	private ImageIcon hunterImage;
	private ImageIcon grassImage;
	private JLabel rabbitLabel;
	private JLabel foxLabel;
	private JLabel duckLabel;
	private JLabel hunterLabel;
	private JLabel grassLabel;
	private ImageIcon legendImage;
	private FieldStats stats;
	
	/**
	 * Create's a new PictureCounterView. 
	 * Also add the view to the list of views in AbstractModel.
	 * @param simulator
	 */
	public PictureCounterView(Simulator simulator)
	{
		super(simulator);
		setLayout(new FlowLayout());
		
		legendImage = new ImageIcon("Images/Legend.png");
		add(new JLabel(legendImage));
		
		rabbitImage = new ImageIcon("Images/bunny.jpg");
		add(new JLabel(rabbitImage));
		rabbitLabel= new JLabel();
		add(rabbitLabel);
		
		foxImage = new ImageIcon("Images/fox.jpg");
		add(new JLabel(foxImage));
		foxLabel=new JLabel();
		add(foxLabel);
		
		duckImage = new ImageIcon("Images/duck.jpg");
		add(new JLabel(duckImage));
		duckLabel = new JLabel();
		add(duckLabel);
		
		hunterImage = new ImageIcon("Images/hunter.jpg");
		add(new JLabel(hunterImage));
		hunterLabel = new JLabel();
		add(hunterLabel);
		
		grassImage = new ImageIcon("Images/grass.jpg");
		add(new JLabel(grassImage));
		grassLabel = new JLabel();
		add(grassLabel);
	}
	
	/**
	 * Paint's the PictureCounterView.
	 */
	public void paintComponent(Graphics g) {
		g.setColor(new Color(238,238,238));
		Dimension d=getSize();
		g.fillRect(0,0,d.width,d.height);
		stats = getModel().getStats();
		HashMap hashmap = stats.getHashMap();
		try{
			foxCount = ((Counter) hashmap.get(Fox.class)).getCount();
			duckCount = ((Counter) hashmap.get(Duck.class)).getCount();
			hunterCount = ((Counter) hashmap.get(Hunter.class)).getCount();
			rabbitCount = ((Counter) hashmap.get(Rabbit.class)).getCount();
			grassCount = ((Counter) hashmap.get(Grass.class)).getCount();
		}	
		catch(Exception e)
		{
			
		}
		rabbitLabel.setText(((Integer)rabbitCount).toString() +" ");
		foxLabel.setText(((Integer)foxCount).toString()+" ");
		duckLabel.setText(((Integer)duckCount).toString()+" ");
		hunterLabel.setText(((Integer)hunterCount).toString()+" ");
		grassLabel.setText(((Integer)grassCount).toString());
	}
}
